import 'package:get/get.dart';

class CabinetFormBottomMonthLogic extends GetxController {
  List<int> yearList = [];
  List<int> monthList = [];
  List<PickModel> dateList = [];
  int year = 2020;
  int month = 1;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    calculateDate();
  }

  /*
  * 计算时间
  * */
  calculateDate() async {
    int yy = DateTime.now().year;
    int month = DateTime.now().month;
    for (int i = 2020; i <= yy; i++) {
      PickModel model = PickModel();
      model.year = i;
      yearList.add(i);
      int countMonth = 12;
      if (i == yy) {
        countMonth = month;
      }
      List<int> currentModelList = [];
      for (int i = 1; i <= countMonth; i++) {
        currentModelList.add(i);
      }
      if (i == 2020) {
        monthList = currentModelList;
      }
      model.monthList = currentModelList;
      dateList.add(model);
    }
    update();
  }

  /*
  * 选择月份
  * */
  selectMonth(int index) {
    PickModel model = dateList[index];
    year = model.year!;
    month = 1;
    monthList = model.monthList!;
    update(["month"]);
  }
}

class PickModel {
  int? year;
  List<int>? monthList;
  PickModel();
}
